package de.fhk.fst.dvr.recording

import static de.fhk.fst.dvr.recordings.RequestStatus.PENDING
import de.fhk.fst.dvr.recordings.RequestStatus

class RecordingRequestAdminController extends RecordingRequestController {

  def scaffold = RecordingRequest

  def showPending = {
    def allPendingRequests = RecordingRequest.findAllByStatus(PENDING)
    renderRequestList(allPendingRequests)
  }

  def showAvailableRecordings = {
    System.out.println(actionName);
    render(view: "showPending")
  }

  def grantRequest = {
    def recordingRequest = RecordingRequest.findById(params.id)
    recordingRequest.setStatus RequestStatus.GRANTED
    if (recordingRequest.save(flush:true)) {
      flash.message = "request granted"
    } else {
      flash.message = "grant failed"
    }
    redirect(action:"showPending")
  }

  def denyRequest = {
    def recordingRequest = RecordingRequest.findById(params.id)
    recordingRequest.setStatus RequestStatus.DENIED
    if (recordingRequest.save(flush: true)) {
      flash.message = "request denied"
    } else {
      flash.message = "denial failed"
    }
    redirect(view: "showPending")
  }
}
